<!DOCTYPE html>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path ;

%>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
  <meta name="description" content="">
  <meta name="author" content="">
  <link rel="icon" href="IMG/favicon.ico">


  <title>邮件配置</title>

  <!-- Bootstrap core CSS -->
  <link href="static/css/dist/css/bootstrap.min.css?v=1" rel="stylesheet">
  <!-- Bootstrap theme -->
  <link href="static/css/dist/css/bootstrap-theme.min.css" rel="stylesheet">
  <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
  <link href="static/css/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

  <!-- Custom styles for this template -->
  <link href="static/css/theme.css" rel="stylesheet">

  <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
  <script>

    function loadAddModel(){
      //加载页面初始化
      document.getElementById("emailName").value="";
      document.getElementById("emailServer").value="";
      document.getElementById("emailLoginName").value="";
      document.getElementById("emailPassword").value="";
      document.getElementById("emailSubject").value="";
      document.getElementById("emailContent").value="";

    }
    function resetAdd(emailId){
      document.getElementById("addReceiver").value="";
        document.getElementById("emailId").value=emailId;
    }
    function loadDatabaseTable(){
      var tabelName = document.getElementById("");
      tabelName = window.encode
      document.location.href = "<%= basePath %>/iniRuleTable?databaseName=" + tabelName;
    }

    function checkEmailValid(){
        var obj={};
        obj["emailName"]=document.getElementById("emailName").value;
        obj["emailServer"]=document.getElementById("emailServer").value;
        obj["emailPassword"]=document.getElementById("emailPassword").value;
        obj["emailLoginName"]=document.getElementById("emailLoginName").value;
        obj["emailSubject"]=document.getElementById("emailSubject").value;
        obj["emailContent"]=document.getElementById("emailContent").value;

        document.getElementById("emailAdd").innerHTML="";
        $.ajax({
            url: "checkEmailIsValid",
            type: "POST",
            async:false,
            contentType: 'application/json;charset=utf-8', //设置请求头信息
            dataType: "json",
            //data: JSON.stringify(customerArray),    //将Json对象序列化成Json字符串，JSON.stringify()原生态方法
            data: JSON.stringify(obj),            //将Json对象序列化成Json字符串，toJSON()需要引用jquery.json.min.js
            success: function (data) {
                if(data.status=="success"){
                    document.getElementById("addEmail").disabled=false;
                    document.getElementById("emailAdd").innerHTML="测试连接成功";
                }else{
                    document.getElementById("emailAdd").innerHTML=data.info;
                    document.getElementById("addEmail").disabled=true;
                    return false;
                }
            },
            error: function (res) {
                alert(res.responseText);
            }
        });
    }

  </script>
  <!--[if lt IE 9]><script src="static/css/assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
  <script src="static/css/assets/js/ie-emulation-modes-warning.js"></script>

  <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>

  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>



  <![endif]-->
</head>

<body role="document">


<!-- Fixed navbar -->
<jsp:include page="top.jsp" flush="true"/>

<div class="container">

  <div class="panel panel-default">
    <!-- Default panel contents -->
    <div class="panel-heading">
      <span style="font-family:微软雅黑;">
      邮件发送分组配置
        <button type="button" id="loadButton" name="loadButton"  data-toggle="modal" data-target="#addModal" onClick="loadAddModel()" class="btn btn-default" >
          新增
        </button>
         <span style="color:red">${msg}</span>
      </span>
    </div>
    <div class="panel-body">
      <p><span style="font-family:微软雅黑;">此页面配置你的邮件分组规则，包括用户名，密码，还有发送人。注意：邮件分组名称是唯一的</span> </p>
    </div>
    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="myModalLabel">接收人</h4>
          </div>
          <div class="modal-body" style="font-family:微软雅黑;">
            <form action="<%= basePath %>/addPutEmailName" method="post" name="addEmailPutAdd">

              <div class="row">
                <div class="col-lg-6">
                  <div class="input-group">
                    <input type="text" name="addReceiver" id="addReceiver" class="form-control" placeholder="添加接收人">
                      <span class="input-group-btn">
                        <input type="submit" id="addButton" name="addButton" class="btn btn-default" value="ADD">
                      </span>
                      <input type="hidden" id="emailId" name="emailId" value=""/>
                  </div><!-- /input-group -->
                </div><!-- /.col-lg-6 -->
              </div>

            </form>
          </div>

        </div>
      </div>
    </div>

    <!--Model ALL-->
    <!-- Modal -->
    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="addModalLabel">添加邮件发送分组配置</h4>
          </div>
          <div class="modal-body" style="font-family:微软雅黑;">
            <form class="form-horizontal" action="<%= basePath %>/emailIntoAdd" method="post" name="addData">
              <div class="form-group">
                <label for="emailName" class="col-sm-2 control-label">邮件发送分组名</label>
                <div class="col-sm-10">
                  <input name="emailName" type="text" class="form-control" id="emailName" placeholder="用于配置发送任务时，显示已配置的邮件发送分组名">
                </div>
              </div>

              <div class="form-group">
                <label for="emailServer" class="col-sm-2 control-label">邮件服务器</label>
                <div class="col-sm-10">
                  <input name="emailServer" type="text" class="form-control" id="emailServer"  value="smtp.189.cn" placeholder="smtp.189.cn" >
                </div>
              </div>
              <div class="form-group">
                <label for="emailLoginName" class="col-sm-2 control-label">邮件发送人邮箱</label>
                <div class="col-sm-10">
                  <input name="emailLoginName" type="email" class="form-control" id="emailLoginName" placeholder="填写你的用于发送邮件的邮箱">
                </div>
              </div>
              <div class="form-group">
                <label for="emailPassword" class="col-sm-2 control-label">发送人邮箱密码</label>
                <div class="col-sm-10">
                  <input name="emailPassword" type="password" class="form-control" id="emailPassword" placeholder="填写你的用于发送邮件的密码">
                </div>
              </div>
              <div class="form-group">
                <label for="emailSubject" class="col-sm-2 control-label">邮件主题</label>
                <div class="col-sm-10">
                  <input name="emailSubject" type="text" class="form-control" id="emailSubject" placeholder="邮件主题">
                </div>
              </div>
              <div class="form-group">
                <label for="emailContent" class="col-sm-2 control-label">邮件内容</label>
                <div class="col-sm-10">

                  <textarea class="form-control" name="emailContent" name="emailContent" id="emailContent" rows="3"></textarea>
                </div>
              </div>

              <div class="form-group" align="right">
                  <span id="emailAdd"></span>
                <button type="submit" id="addEmail" name="addEmail"  class="btn btn-default" disabled >添加</button>
                  <button type="button" id="checkButton" name="checkButton" onClick="checkEmailValid()" class="btn btn-primary" >
                      检测
                  </button>
                &nbsp;&nbsp;&nbsp;
              </div>
            </form>

          </div>

        </div>
      </div>
    </div>
    <!-- Table -->
    <table class="table" style="font-family:微软雅黑;table-layout:fixed;" >
      <tr>

        <th>序号</th>
        <th>邮件分组名</th>
        <th>邮件服务器</th>
        <th>发送人邮箱</th>
        <th>邮件主题</th>
        <th>邮件内容</th>
        <th>邮件接收人</th>
        <th>操作</th>

      </tr>
      <%int i=0;%>
      <c:forEach items="${emailList}" var="list">
      <tr>

        <td><%=++i%></td>
        <td>${list.emailName}</td>
        <td>${list.smtpServer}</td>
        <td>${list.smtpUser}</td>
        <td>${list.emailSubject}</td>
        <td>${list.emailContent}</td>
        <td><a href="javascript:void(0)"  data-toggle="modal" data-target="#myModal" onclick="resetAdd('${list.emailModelId}')">添加</a>|<a href="<%= basePath %>/loadPutEmailName?emailId=${list.emailModelId}">查看</a></td>
        <th><a href="<%= basePath %>/emailIntoPage?emailId=${list.emailModelId}&method=delete">删除</a></th>
      </tr>
      </c:forEach>

    </table>
  </div>

</div> <!-- /container -->


<jsp:include page="bottom.jsp" flush="true"/>


<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->

<script src="static/js/jquery.min.js"></script>
<script src="static/css/dist/js/bootstrap.min.js"></script>
<script src="static/css/assets/js/docs.min.js"></script>
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="static/css/assets/js/ie10-viewport-bug-workaround.js"></script>
<!--
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
-->
</body>
</html>
